import * as _prev from "./_prev";
import * as kcoder from "k-coder";
import fs from "fs";
import MsgCfg from "./config/MsgCfg";
import msgCoder from "./common/msgCoder";
import MsgStruct from "./config/MsgStruct";
import path from "path";
import SvrCfg, { EnvType } from "./config/SvrCfg";
import { initHotfix } from "./common/hotfix";
import { initMsg, MsgCoder } from "./config/Msg";
import { initMysql } from "./common/db";
import { initSvrs } from "./common/initSvrs";
import { initXlsx, loadData } from "./config/Xlsx";
import { kilom } from "kilom";
_prev;

(async () => {

    //创建框架app
    const app = kilom.createApp({
        svrCfg: SvrCfg,
        msgCfg: MsgCfg
    });

    //数据库
    await initMysql(app);

    //加载表配置和协议
    initXlsx(kcoder);
    initMsg(kcoder);
    loadData(fs.readFileSync(path.resolve(__dirname, "../config/data.bin")));
    MsgCoder.loadAll(MsgStruct);

    //框架设置
    app.miscCfg.msgCoder = msgCoder;
    app.miscCfg.autoReloadHandler = app.env === EnvType.development;
    app.miscCfg.reloadMsgCfgPath = path.resolve(__dirname, "config/MsgCfg");
    app.miscCfg.logger = (level, msg) => {
        console.log(msg);
    };

    //启动
    app.start(async () => {
        await initSvrs(app);
        initHotfix(app);
    });

})();